package com.FH.applyFrom.office;

import com.FH.applyForm.officeServies.OfficeFirst_Type.OfficeFirstResource;
import com.FH.applyForm.officeServies.condtion.CondtionResource;
import com.FH.applyForm.officeServies.office_name.OfficeNamePullDTO;
import com.FH.applyForm.officeServies.office_name.OfficeNameResource;
import com.FH.organization.operator_log.OperatorLogPullDTO;
import com.FH.organization.operator_log.OperatorLogResource;
import com.FH.organization.suggestion.SuggestionResource;
import com.FH.organization.work_flow.WorkFlowPullDTO;
import com.FH.organization.work_flow.WorkFlowResource;
import com.FH.organization.work_flow.WorkFlowShowDTO;
import com.FH.organization.work_flow_history.WorkFlowHistoryResource;
import com.FH.util.AccessDB;
import com.FH.util.ResultDTO;
import com.FH.util.warnSrc;
import org.codehaus.jettison.json.JSONArray;
import org.codehaus.jettison.json.JSONObject;

import javax.ejb.Stateless;
import javax.inject.Inject;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.UUID;

/**
 * Created by penglufei
 * 办公用品接口实现类
 */
@Stateless
public class OfficeDAOImpl extends AccessDB implements OfficeDAO {

    @Inject
    OperatorLogResource operatorLogResource;
    @Inject
    OfficeResource officeResource;
    @Inject
    OfficeFirstResource officeFirstResource;
    @Inject
    OfficeNameResource officeNameResource;
    @Inject
    CondtionResource condtionResource;
    @Inject
    SuggestionResource suggestionResource;
    @Inject
    WorkFlowHistoryResource workFlowHistoryResource;
    @Inject
    WorkFlowResource workFlowResource;

    /**
     * 获取部门信息类
     * @param search
     * @param page
     * @param size
     * @return
     */

    @Override
    public ResultDTO getOfficeInfo(String search, String page, String size) {

        ResultDTO resultDTO=new ResultDTO();

        try {

            JSONObject json = new JSONObject(search);
            String existName = "0";

            String sqlexit = "select count(1) from officetools_form  where 1=1 ";

            String sql_w = "";//查询条件sql组合
            String sql_page = "";//分页组合

            Integer page_ok = Integer.parseInt(page);//将定义page、size的String类型转换成Integer类型
            Integer size_ok = Integer.parseInt(size);

            if (page.equals("1")) {
                sql_page = " limit 0," + size + "";
            } else {
                sql_page = " limit " + ((page_ok - 1)*size_ok) + "," + size + "";
            }
            if(json.has("isverify")){
                sql_w += " AND isverify ='" + json.getString("isverify")+"'";
            }
//            else{
//                sql_w += " AND (isverify IS NULL OR isverify=0)";
//            }

            if (json.has("member_id")) {
                sql_w += " AND member_id = '" + json.getString("member_id")+"'";
            }
            if (json.has("officetools_form_spec")) {
                sql_w += " AND officetools_form_spec like '%" + json.getString("officetools_form_spec") + "%'";
            }
            if(json.has("officetools_form_id")){
                sql_w += " AND officetools_form_id = '" + json.getString("officetools_form_id")+"'";
            }


            String sql_ok = sqlexit + sql_w;//组合好的sql语句
            existName = getReportingToOne(sql_ok);

            List<String[]> seresult = new ArrayList<String[]>();

            List<OfficeShowDTO> result = new ArrayList<OfficeShowDTO>();

            if(!existName.equals("0")){
                String sql ="select officetools_form_id,officetools_form_note,member_id,parent_officetools_form_id,isverify,fail_resource,officetools_id,officetools_date,isstock,isnorm,office_first,office_second " +
                        " FROM officetools_form WHERE 1=1 "+sql_w +" ORDER BY officetools_date DESC"+ sql_page;
                seresult = this.getReportingTo(sql);

                //构建返回对象
                for (int i = 0; i < seresult.size(); i++){
                    OfficeShowDTO office = new OfficeShowDTO();
                    office.setOfficetools_id(seresult.get(i)[1]);
                    office.setOfficetools_form_note(seresult.get(i)[2]);
                    office.setMember_id(seresult.get(i)[3]);
                    office.setParent_officetools_form_id(seresult.get(i)[4]);
                    office.setIsverify(seresult.get(i)[5]);
                    office.setFail_resource(seresult.get(i)[6]);
                    String officetools_id = seresult.get(i)[7];
                    office.setOfficetools_id(officetools_id);
                    office.setOfficetools_date(seresult.get(i)[8]);
                    office.setIsstock(seresult.get(i)[9]);
                    office.setIsnorm(seresult.get(i)[10]);
                    office.setOffice_first(seresult.get(i)[11]);
                    office.setOffice_second(seresult.get(i)[12]);

                    office.setUpdatetime(seresult.get(i)[11]);
                    ResultDTO worklist=null,officetype=null,suggestion=null,reportmen=null,reportdepart=null;
                    if(json.has("isverify")){
                        String state=json.getString("isverify");
                        worklist=workFlowResource.getWorkFlowInfo("{work_flow_formid:"+seresult.get(i)[1]+",work_flow_state:"+state+"}","1","20");
                    }else{
                        worklist=workFlowResource.getWorkFlowInfo("{work_flow_formid:"+seresult.get(i)[1]+"}","1","20");
                    }
                    office.setWs(worklist.getValues());

//                    if(officetools_id!=null&&!officetools_id.equals("")){
//                        //获取他的父id
//                        List<String []> menu = new ArrayList<String []>();
//
//                        List<OfficeToolsShowDTO> menuDTO = new ArrayList<OfficeToolsShowDTO>();
//
//                        String parent_sql="select officetools_id ,officetools_name,officetools_price,office_id from officetools_manage where officetools_id='"+officetools_id+"'";
//                        menu=this.getReportingTo(parent_sql);
//                        for(int j=0;j<menu.size();j++) {
//
//                            OfficeToolsShowDTO sysmenuShowDTO1 = new OfficeToolsShowDTO();
//                            sysmenuShowDTO1.setOfficetools_id(menu.get(j)[1]);
//                            sysmenuShowDTO1.setOfficetools_name(menu.get(j)[2]);
//                            sysmenuShowDTO1.setOfficetools_price(menu.get(j)[3]);
//                            sysmenuShowDTO1.setOffice_id(menu.get(j)[4]);
//
//                            menuDTO.add(sysmenuShowDTO1);
//
//                        }
//                        office.setQq(menuDTO);
//
//                    }
                    if(seresult.get(i)[1] != null && ! seresult.get(i)[1].equals("")){

                        suggestion=suggestionResource.getSuggestionInfo("{form_id:" + seresult.get(i)[1] + "}", "1", "100");
                        office.setSuggestionShowDTOs(suggestion.getValues());
                    }
                    officetype=officeNameResource.getOfficeNameInfo("{office_form_id:"+seresult.get(i)[1]+"}","1","1000");
                    office.setWw(officetype.getValues());

                  result.add(office);
                }
            }

            if(seresult.size()!=0) {
                resultDTO.setStatus("90000");
                resultDTO.setDescritpion(warnSrc.get_success);
            }else {
                resultDTO.setStatus("90001");
                resultDTO.setDescritpion(warnSrc.get_fail);
            }
            resultDTO.setStr(result.size()+"");
            resultDTO.setValues(result);
                } catch (Exception e){
            e.printStackTrace();
        }

        return resultDTO;
    }

    /**
     * 查询是否还有库存信息
     * @param search
     * @param page
     * @param size
     * @return
     */
    @Override
    public ResultDTO getOfficeKucunInfo(String search, String page, String size) {
        ResultDTO resultDTO=new ResultDTO();

        try {

            JSONObject json = new JSONObject(search);
            String existName = "0";

            String sqlexit = "select count(1) from isstock  where 1=1 ";

            String sql_w = "";//查询条件sql组合
            String sql_page = "";//分页组合

            Integer page_ok = Integer.parseInt(page);//将定义page、size的String类型转换成Integer类型
            Integer size_ok = Integer.parseInt(size);

            if (page.equals("1")) {
                sql_page = " limit 0," + size + "";
            } else {
                sql_page = " limit " + ((page_ok - 1)*size_ok) + "," + size + "";
            }

            if(json.has("id")){
                sql_w += " AND id = '" + json.getString("id")+"'";
            }

            String sql_ok = sqlexit + sql_w;//组合好的sql语句
            existName = getReportingToOne(sql_ok);

            List<String[]> seresult = new ArrayList<String[]>();

            List<OfficeShowDTO> result = new ArrayList<OfficeShowDTO>();

            if(!existName.equals("0")){
                String sql ="select id,isstock FROM isstock WHERE 1=1 "+sql_w +" ORDER BY id DESC"+ sql_page;
                seresult = this.getReportingTo(sql);

                //构建返回对象
                for (int i = 0; i < seresult.size(); i++){
                    OfficeShowDTO office = new OfficeShowDTO();
                    office.setId(seresult.get(i)[1]);
                    office.setIsstock(seresult.get(i)[2]);


                    result.add(office);
                }
            }

            if(seresult.size()!=0) {
                resultDTO.setStatus("90000");
                resultDTO.setDescritpion(warnSrc.get_success);
            }else {
                resultDTO.setStatus("90001");
                resultDTO.setDescritpion(warnSrc.get_fail);
            }
            resultDTO.setStr(result.size()+"");
            resultDTO.setValues(result);
        } catch (Exception e){
            e.printStackTrace();
        }

        return resultDTO;
    }

    /**
     * 查询是否超标
     * @param search
     * @param page
     * @param size
     * @return
     */
    @Override
    public ResultDTO getOfficeBiaoZhunInfo(String search, String page, String size) {
        ResultDTO resultDTO=new ResultDTO();

        try {

            JSONObject json = new JSONObject(search);
            String existName = "0";

            String sqlexit = "select count(1) from isnorm  where 1=1 ";

            String sql_w = "";//查询条件sql组合
            String sql_page = "";//分页组合

            Integer page_ok = Integer.parseInt(page);//将定义page、size的String类型转换成Integer类型
            Integer size_ok = Integer.parseInt(size);

            if (page.equals("1")) {
                sql_page = " limit 0," + size + "";
            } else {
                sql_page = " limit " + ((page_ok - 1)*size_ok) + "," + size + "";
            }

            if(json.has("id")){
                sql_w += " AND id = '" + json.getString("id")+"'";
            }

            String sql_ok = sqlexit + sql_w;//组合好的sql语句
            existName = getReportingToOne(sql_ok);

            List<String[]> seresult = new ArrayList<String[]>();

            List<OfficeShowDTO> result = new ArrayList<OfficeShowDTO>();

            if(!existName.equals("0")){
                String sql ="select id,isnorm FROM isnorm WHERE 1=1 "+sql_w +" ORDER BY id DESC"+ sql_page;
                seresult = this.getReportingTo(sql);

                //构建返回对象
                for (int i = 0; i < seresult.size(); i++){
                    OfficeShowDTO office = new OfficeShowDTO();
                    office.setId(seresult.get(i)[1]);
                    office.setIsnorm(seresult.get(i)[2]);


                    result.add(office);
                }
            }

            if(seresult.size()!=0) {
                resultDTO.setStatus("90000");
                resultDTO.setDescritpion(warnSrc.get_success);
            }else {
                resultDTO.setStatus("90001");
                resultDTO.setDescritpion(warnSrc.get_fail);
            }
            resultDTO.setStr(result.size()+"");
            resultDTO.setValues(result);
        } catch (Exception e){
            e.printStackTrace();
        }

        return resultDTO;
    }
    /**
     * 办公用品增加实现类
     * @param dataDTO
     * @return
     */
    @Override
    public ResultDTO addOfficeInfo(OfficePullDTO dataDTO) {

        ResultDTO resultDTO = new ResultDTO();//构建返回对象

        String existName = "";

        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//设置日期格式

        String uuid = UUID.randomUUID().toString().trim().replaceAll("-", "");

        String officetools_form_id = dataDTO.getOfficetools_form_id();

        String manage_id = dataDTO.getManage_id();

        /**
         * 判断advance_form_id是否为空
         *
         *       不为空的情况下执行修改方法，
         *
         *       为空得情况下，执行执行此方法
         */

        //构建返回对象


        if(officetools_form_id!=null&&!officetools_form_id.equals("")){

            String sql = "select count(1) from officetools_form where officetools_form_id='"+dataDTO.getOfficetools_form_id()+"'";

            existName=getReportingToOne(sql);

            if(!existName.equals("0")) {
                return updateOfficeInfo(dataDTO);
            }
        }

        String office_insert = "";

            //构建插入sql
        office_insert +="INSERT INTO officetools_form(officetools_form_id," +
                    "officetools_form_note,member_id,parent_officetools_form_id,isverify,fail_resource,officetools_date,isnorm,isstock,updatetime,office_first,office_second)"+
                    "VALUES('"+uuid+ "','"+dataDTO.getOfficetools_form_note()+"','"+dataDTO.getMember_id()+"','"
                    +dataDTO.getParent_officetools_form_id()+"','0','" +" "+"','" + df.format(new Date()) + "','0','0','" +" "+"','" + dataDTO.getOffice_first() + "','" + dataDTO.getOffice_second() + "')";
            //插入业务表
           int resultls =  addReportingTo(office_insert);


        if(resultls!=0) {
            resultDTO.setStr(uuid);
            resultDTO.setStatus("90000");
            resultDTO.setDescritpion(warnSrc.add_success);

            /**
             * JSON解析集合、参会人
             */
            if(null!=dataDTO.getOfficetype()&& !"".equals(dataDTO.getOfficetype())){
                String officetype=dataDTO.getOfficetype();
                try {
                    JSONArray array=new JSONArray(officetype);
                    if(array!=null&&array.length()>0){
                        List<OfficePullDTO> result = new ArrayList<OfficePullDTO>();
                        for(int i = 0; i < array.length(); i++){
                            JSONObject jsonObject=array.getJSONObject(i);
                            String id=jsonObject.getString("id");
                            String name=jsonObject.getString("name");
                            String number=jsonObject.getString("selectnumber");
                            String price=jsonObject.getString("price");
                            OfficeNamePullDTO officeNamePullDTO = new OfficeNamePullDTO();
                            officeNamePullDTO.setOffice_form_id(uuid);
                            officeNamePullDTO.setOffice_id(id);
                            officeNamePullDTO.setOffice_name(name);
                            officeNamePullDTO.setOfficetools_number(number);
                            officeNamePullDTO.setOfficetools_price(price);
                            officeNameResource.addOfficeNameInfo(officeNamePullDTO);
                        }
                    }

                } catch (Exception e) {
                    e.printStackTrace();
                }

            }


            //操作日志
            OperatorLogPullDTO operatorlogPullDTO=new OperatorLogPullDTO();
            operatorlogPullDTO.setWork_form_id(uuid);
            operatorlogPullDTO.setOperator_log_type("办公用品申请");
            operatorlogPullDTO.setOperator_log_title(dataDTO.getOfficetools_form_name());
            operatorlogPullDTO.setOperator_log_content(dataDTO.getOfficetools_form_spec());
            operatorlogPullDTO.setMember_id(dataDTO.getMember_id());
            operatorLogResource.addOperatorLogInfo(operatorlogPullDTO);

            //流程上报

            WorkFlowPullDTO workFlowPullDTO=new WorkFlowPullDTO();
            workFlowPullDTO.setWork_flow_formid(uuid);
            workFlowPullDTO.setWork_flow_type("officetools_form");
            workFlowPullDTO.setWork_flow_desc("办公用品申请请求审批");
            workFlowPullDTO.setWork_flow_date(df.format(new Date()));
            workFlowPullDTO.setWork_flow_order("0");
            workFlowPullDTO.setWork_flow_createid(dataDTO.getMember_id());
            workFlowPullDTO.setWork_flow_approval(dataDTO.getReport_people());
            workFlowPullDTO.setWork_flow_approval_organization_id(dataDTO.getWork_flow_approval_organization_id());
            workFlowPullDTO.setFlow_path_id(dataDTO.getFlow_path_id());
            workFlowPullDTO.setWork_flow_suggestion("");
            workFlowResource.addWorkFlowInfo(workFlowPullDTO);


        }else{
            resultDTO.setStatus("90001");
            resultDTO.setDescritpion(warnSrc.add_fail);
        }

        return resultDTO;
    }

    @Override
    public ResultDTO getParent_officetools_form_idInfo(String member_id) {

        ResultDTO resultDTO = new ResultDTO();

        List<String[]> seresult=null;

        //判断用户名是否存在
        if (null != member_id) {

            String sqlexit = "select officetools_form_id from officetools_form where member_id ='" + member_id + "' and (parent_officetools_form_id='NULL' OR parent_officetools_form_id='');";

            seresult = this.getReportingTo(sqlexit);

            if(seresult != null&&seresult.size()>0) {
                resultDTO.setStr(seresult.get(0)[1]);
            }

        }

        if (seresult.size() != 0) {
            resultDTO.setStatus("90000");//
            resultDTO.setDescritpion(warnSrc.get_success);

        } else {
            resultDTO.setStatus("90001");//
            resultDTO.setDescritpion(warnSrc.get_fail);
        }


        return resultDTO;
    }

    /**
     * 调用修改方法时  先调用此删除方法  删除所有的此类别
     *
     * 然后调用add添加方法   重新添加一次
     * @param officePullDTO
     * @return
     */
    @Override
    public ResultDTO deleteOfficeInfo(OfficePullDTO officePullDTO) {

        //删除之前查询是否有该数据
        String sql = "select count(1) from officetools_form where officetools_form_id='"+officePullDTO.getOfficetools_form_id()+"'";
        String existName = getReportingToOne(sql);

        int result = 0;

        ResultDTO resultDTO = new ResultDTO();

        if(existName!=null){
            String QUERY = "";
            QUERY += "delete from officetools_form where officetools_form_id='"+officePullDTO.getOfficetools_form_id()+"'";
            result = this.addReportingTo(QUERY);
        }
        if(result!=0){

                resultDTO.setStatus("90000");
                resultDTO.setDescritpion(warnSrc.delete_success);

            OfficeNamePullDTO officeNamePullDTO = new OfficeNamePullDTO();
            officeNamePullDTO.setOffice_form_id(officePullDTO.getOfficetools_form_id());
            officeNameResource.deleteOfficeNameInfo(officeNamePullDTO);

            WorkFlowPullDTO workFlowPullDTO=new WorkFlowPullDTO();
            workFlowPullDTO.setWork_flow_formid(officePullDTO.getOfficetools_form_id());
            workFlowResource.deleteWorkFlowInfo(workFlowPullDTO);


        }else{
            resultDTO.setStatus("90001");
            resultDTO.setDescritpion(warnSrc.delete_fail);
        }

        return resultDTO;
    }

    /**
     * 修改办公用品信息
     * @param officePullDTO
     * @return
     */
    @Override
    public ResultDTO updateOfficeInfo(OfficePullDTO officePullDTO) {
        ResultDTO resultDTO = new ResultDTO();

        /**
         * 先删除类别表
         *
         * 再进行添加
         */
        ResultDTO resultss = null;
        String office_form_id = officePullDTO.getOfficetools_form_id();
        OfficeNamePullDTO officeNamePullDTO=new OfficeNamePullDTO();
        officeNamePullDTO.setOffice_form_id(office_form_id);
        officeNameResource.deleteOfficeNameInfo(officeNamePullDTO);
        //  if(resultss!=null){
        if (null != officePullDTO.getOfficetype() && !"".equals(officePullDTO.getOfficetype())) {
            String officetype = officePullDTO.getOfficetype();
            try {
                JSONArray array = new JSONArray(officetype);
                if (array != null && array.length() > 0) {
                    List<OfficePullDTO> result = new ArrayList<OfficePullDTO>();
                    for (int i = 0; i < array.length(); i++) {
                        JSONObject jsonObject = array.getJSONObject(i);
                        String id = jsonObject.getString("id");
                        String name = jsonObject.getString("name");
                        String number = jsonObject.getString("selectnumber");
                        String price = jsonObject.getString("price");
                        OfficeNamePullDTO meetingPullDTO = new OfficeNamePullDTO();
                        meetingPullDTO.setOffice_form_id(officePullDTO.getOfficetools_form_id());
                        meetingPullDTO.setOffice_id(id);
                        meetingPullDTO.setOffice_name(name);
                        meetingPullDTO.setOfficetools_number(number);
                        meetingPullDTO.setOfficetools_price(price);
                        officeNameResource.addOfficeNameInfo(meetingPullDTO);
                    }
                }

            } catch (Exception e) {
                e.printStackTrace();
            }

        }


        String QUERY = "";

        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String time = df.format(new Date());

        //更新sql语句
        QUERY += "update officetools_form set updatetime = '" + time + "'";
        if(null!=officePullDTO.getOfficetools_form_note()&&!"".equals(officePullDTO.getOfficetools_form_note())){
            QUERY += ",officetools_form_note ='" + officePullDTO.getOfficetools_form_note() + "'";
        }

        if(null!=officePullDTO.getOfficetools_form_bigprice()&&!"".equals(officePullDTO.getOfficetools_form_bigprice())){
            QUERY += ",officetools_form_bigprice ='" + officePullDTO.getOfficetools_form_bigprice() + "'";
        }

        if(null!=officePullDTO.getFail_resource()&&!"".equals(officePullDTO.getFail_resource())){
            QUERY += ",fail_resource ='" + officePullDTO.getFail_resource() + "'";
        }
        if(null!=officePullDTO.getIsnorm()&&!"".equals(officePullDTO.getIsnorm())){
            QUERY += ",isnorm ='" + officePullDTO.getIsnorm() + "'";
        }

        if(null!=officePullDTO.getIsstock()&&!"".equals(officePullDTO.getIsstock())){
            QUERY += ",isstock ='" + officePullDTO.getIsstock() + "'";
        }
        if(null!=officePullDTO.getIsverify()&&!"".equals(officePullDTO.getIsverify())){
            QUERY += ",isverify ='" + officePullDTO.getIsverify() + "'";
        }
        if(null!=officePullDTO.getOffice_first()&&!"".equals(officePullDTO.getOffice_first())){
            QUERY += ",office_first ='" + officePullDTO.getOffice_first() + "'";
        }
        if(null!=officePullDTO.getOffice_second()&&!"".equals(officePullDTO.getOffice_second())){
            QUERY += ",office_second ='" + officePullDTO.getOffice_second() + "'";
        }
//
//        if(null!=officePullDTO.yuliu&&!"".equals(officePullDTO.yuliu)){
//            QUERY += ",yuliu ='" + officePullDTO.getYuliu() + "'";
//        }

        QUERY += " where officetools_form_id = '" + officePullDTO.getOfficetools_form_id() + "'";


        int result = this.addReportingTo(QUERY);

        // 判断SQl是否执行成功
        if (result != 0) {
            resultDTO.setStr(office_form_id);
            WorkFlowPullDTO workFlowPullDTO=new WorkFlowPullDTO();
            workFlowPullDTO.setWork_flow_formid(officePullDTO.getOfficetools_form_id());
            workFlowPullDTO.setWork_flow_approval(officePullDTO.getReport_people());
            workFlowPullDTO.setWork_flow_approval_organization_id(officePullDTO.getWork_flow_approval_organization_id());
            workFlowPullDTO.setIsverify("0");
            workFlowResource.updateWorkFlowInfo(workFlowPullDTO);



            resultDTO.setStatus("90000");//
            resultDTO.setDescritpion(warnSrc.update_success);
        } else {
            resultDTO.setStatus("90001");//
            resultDTO.setDescritpion(warnSrc.update_fail);
        }
        return resultDTO;
    }

    /**
     * 修改字段
     * @param officePullDTO
     * @return
     */
    @Override
    public ResultDTO updateOfficeOthersInfo(OfficePullDTO officePullDTO) {
        ResultDTO resultDTO = new ResultDTO();

        String QUERY = "";

        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String time = df.format(new Date());

        //更新sql语句
        QUERY += "update officetools_form set updatetime = '" + time + "'";
        if(null!=officePullDTO.getOfficetools_form_note()&&!"".equals(officePullDTO.getOfficetools_form_note())){
            QUERY += " officetools_form_note ='" + officePullDTO.getOfficetools_form_note() + "'";
        }

        if(null!=officePullDTO.getOfficetools_form_bigprice()&&!"".equals(officePullDTO.getOfficetools_form_bigprice())){
            QUERY += ",officetools_form_bigprice ='" + officePullDTO.getOfficetools_form_bigprice() + "'";
        }

        if(null!=officePullDTO.getFail_resource()&&!"".equals(officePullDTO.getFail_resource())){
            QUERY += ",fail_resource ='" + officePullDTO.getFail_resource() + "'";
        }
        if(null!=officePullDTO.getIsnorm()&&!"".equals(officePullDTO.getIsnorm())){
            QUERY += ",isnorm ='" + officePullDTO.getIsnorm() + "'";
        }

        if(null!=officePullDTO.getIsstock()&&!"".equals(officePullDTO.getIsstock())){
            QUERY += ",isstock ='" + officePullDTO.getIsstock() + "'";
        }
        if(null!=officePullDTO.getIsverify()&&!"".equals(officePullDTO.getIsverify())){
            QUERY += ",isverify ='" + officePullDTO.getIsverify() + "'";
        }

        if(null!=officePullDTO.getOffice_first()&&!"".equals(officePullDTO.getOffice_first())){
            QUERY += ",office_first ='" + officePullDTO.getOffice_first() + "'";
        }
        if(null!=officePullDTO.getOffice_second()&&!"".equals(officePullDTO.getOffice_second())){
            QUERY += ",office_second ='" + officePullDTO.getOffice_second() + "'";
        }
//
//        if(null!=officePullDTO.yuliu&&!"".equals(officePullDTO.yuliu)){
//            QUERY += ",yuliu ='" + officePullDTO.getYuliu() + "'";
//        }

        QUERY += " where officetools_form_id = '" + officePullDTO.getOfficetools_form_id() + "'";


        int result = this.addReportingTo(QUERY);

        // 判断SQl是否执行成功
        if (result != 0) {

//            WorkFlowPullDTO workFlowPullDTO=new WorkFlowPullDTO();
//            workFlowPullDTO.setWork_flow_formid(officePullDTO.getOfficetools_form_id());
//            workFlowPullDTO.setWork_flow_approval(officePullDTO.getReport_people());
//            workFlowResource.updateWorkFlowInfo(workFlowPullDTO);

            resultDTO.setStatus("90000");//
            resultDTO.setDescritpion(warnSrc.update_success);
        } else {
            resultDTO.setStatus("90001");//
            resultDTO.setDescritpion(warnSrc.update_fail);
        }
        return resultDTO;
    }

    /***
     * 暂存方法
     * @param officePullDTO
     * @return
     */
    @Override
    public ResultDTO temporaryStorageOfficeOthersInfo(OfficePullDTO officePullDTO) {

        ResultDTO resultDTO = new ResultDTO();

        //获取申请流程
        List<WorkFlowShowDTO> list = workFlowResource.getWorkFlowInfo("{work_flow_formid:"+officePullDTO.getOfficetools_form_id()+"}","1","1").getValues();

//            //先删除原下一步审核记录
//            String delete_record = "DELETE FROM work_flow_history WHERE work_flow_id = '"+list.get(0).getWork_flow_id()+"' AND work_flow_formid = '"
//                                    +list.get(0).getWork_flow_formid()+"' AND work_flow_date = '"+list.get(0).getWork_flow_date()+"'";
//
//            addReportingTo(delete_record);

        //添加流程审核暂存记录
//            WorkFlowHistoryPullDTO workFlowHistoryPullDTO = new WorkFlowHistoryPullDTO();
//            workFlowHistoryPullDTO.setWork_flow_id(list.get(0).getWork_flow_id());
//            workFlowHistoryPullDTO.setWork_flow_formid(officePullDTO.getOfficetools_form_id());
//            workFlowHistoryPullDTO.setWork_flow_approval_organization_id(list.get(0).getWork_flow_approval_organization_id());
//            workFlowHistoryPullDTO.setWork_flow_approval(officePullDTO.getMember_id());
//            workFlowHistoryPullDTO.setWork_flow_type(list.get(0).getWork_flow_type());
//            workFlowHistoryPullDTO.setWork_flow_suggestion(officePullDTO.getFail_resource());
//            workFlowHistoryPullDTO.setWork_flow_date(time);
//            workFlowHistoryPullDTO.setWork_flow_finish_date(time);
//
//            workFlowHistoryResource.addWorkFlowHistoryInfo(workFlowHistoryPullDTO);

        WorkFlowPullDTO workFlowPullDTO = new WorkFlowPullDTO();
        workFlowPullDTO.setWork_flow_id(list.get(0).getWork_flow_id());
        workFlowPullDTO.setWork_flow_formid(list.get(0).getWork_flow_formid());
        workFlowPullDTO.setDesc(officePullDTO.getFail_resource());
        workFlowPullDTO.setWork_flow_approval(list.get(0).getWork_flow_approval());
        workFlowPullDTO.setWork_flow_approval_organization_id(list.get(0).getWork_flow_approval_organization_id());
        workFlowPullDTO.setWork_flow_type(list.get(0).getWork_flow_type());

        resultDTO = workFlowResource.updateWorkFlowInfo(workFlowPullDTO);

        return resultDTO;
    }
}
